//
//  NetWorkingSModel.m
//  WebView
//
//  Created by XDD on 16/5/31.
//  Copyright © 2016年 XDD. All rights reserved.
//

#import "NetWorkingSModel.h"
#import "Globels.h"

@implementation NetWorkingSModel

- (void)userGetCode:(NSMutableDictionary *)dic {
    
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:getCode WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:GetCode];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//登陆
- (void)userGetLogin:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:login WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:Login];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//获取个人信息
- (void)userGetUserinfo:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:userinfo WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:Userinfo];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//编辑个人信息
- (void)userGetEdit_Userinfo:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:edit_userinfo WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:Edit_Userinfo];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//上传头像
- (void)userGetHeadImg:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:headimg WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:HeadImg];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//我的发布
- (void)userGetMy_issue:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:my_issue WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:My_issue];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//我的志愿活动
- (void)userGetMy_act:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:my_act WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:My_act];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//我的救助
- (void)userGetMy_help:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:my_help WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:My_help];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//信息查询
- (void)homeAppGetget_message:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:get_message WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:Get_message];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//关爱活动
- (void)homeAppGetactivity:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:activity WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:Activity];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//志愿者
- (void)homeAppGetaccorder:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:accorder WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:Accorder];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//信息公示
- (void)homeAppGetmsg_open:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:msg_open WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:Msg_open];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//首页轮播
- (void)homeAppGetHome_img:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:home_img WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:Home_img];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//发布需求
- (void)homeAppGetpublish_help:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:publish_help WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:Publish_help];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//支付申请
- (void)PayappGetpay_ask:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:pay_ask WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:Pay_ask];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

//报名成为志愿者
- (void)PayappGetApply_volunteer:(NSMutableDictionary *)dic {
    __block NetWorkingSModel *weakSelf = self;
    [NetRequestClass NetCommonRequest:dic withUrl:apply_volunteer WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf fetchValueSuccessWithData:returnValue with:Apply_volunteer];
        
    } WithErrorCodeBlock:^(id errorCode) {
        
        self.errorBlock(errorCode);
    }];
}

#pragma mark -- 数据返回处理
- (void)fetchValueSuccessWithData:(id)data with:(interface_personal)method {
    NSDictionary *dataDic = [Globels dictionaryWithJsonString:data];
    NSString *statu = [dataDic objectForKey:@"statu"];
//    NSString *result = [dataDic objectForKey:@"result"];
    
    switch (method) {
        case GetCode:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case Login:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                NSLog(@"%@",dataDic[@"result"]);
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case Userinfo:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case Edit_Userinfo:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                NSLog(@"%@",dataDic[@"result"]);
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case HeadImg:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case My_issue:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case My_act:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case My_help:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case Get_message:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                NSLog(@"%@",dataDic[@"result"]);
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case Activity:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case Accorder:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case Msg_open:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case Home_img:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case Publish_help:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                NSLog(@"%@",dataDic);
                NSLog(@"%@",dataDic[@"result"]);

                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case Pay_ask:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                NSLog(@"%@",dataDic);
                NSLog(@"%@",dataDic[@"result"]);
                
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
        case Apply_volunteer:
            if ([statu integerValue] == 0) {
                
                //获取成功
                self.returnBlock(dataDic);
                NSLog(@"数据请求成功");
            }
            else {
                //获取失败
                NSLog(@"数据请求失败");
                self.errorBlock(dataDic);
                NSLog(@"%@",dataDic);
                NSLog(@"%@",dataDic[@"result"]);
                
                // [SVProgressHUD showInfoStatus:result afterDelay:2.0];
            }
            break;
    }
}

@end
